package cn.sofwin.day0122.homework.hero;

/**
 * 英雄
 * @author 仙女本仙
 * @email 1335651292@qq.com
 */
public class Hero {
    /** 等级 */
    private int lv;

    /** 经验 */
    private int exp;

    /**
     * 无参构造方法
     */
    public Hero(){
        this.exp = 0;
        this.lv = 0;

    }

    /**
     * 带参数的构造方法
     * @param exp 经验值
     */
    public Hero(int exp){
        if(exp < 0){
            System.out.println("经验值不能小于0");
        }else if(exp > count(30)){
            System.out.println("经验值不能大于30级时的最大值");
        }else{
            this.exp = exp;
            int n = 1;
            while(exp >= count(n)){
                this.lv = n++;
            }
        }
    }

    /*public Hero(int exp){
        if(exp >= 0 && exp <= 814420){
            this.exp = exp;
        }else{
            System.out.println("英雄经验值输入错误");
        }

    }
*/

    /*public void show(){
        for (int i = 0; i <= 30; i++) {
            if((30*(i*i*i+5*i)-80) <= this.exp && (30*((i+1)*(i+1)*(i+1)+5*(i+1))-80)>this.exp ){
                this.lv = i;
                break;
            }
        }
        System.out.println("英雄的等级为：" + this.lv +",英雄的经验为：" +this.exp);
    }*/

    private int count(int lv){
        return 30 * (lv * lv * lv + 5 * lv) - 80;
    }

    public void show(){
        System.out.println("英雄等级为：" + this.lv + "经验值为：" + this.exp);
    }



}
